<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数内部的this指向</title>
</head>
<body>
    <button>点击</button>
    <script type="text/javascript">
        //1.普通函数this-Window
        function setDataHtml(){
            console.log(this);
        }
        setDataHtml();
        //2.对象函数中this-指向Object
        var star = {
            username:'刘德华',
            age:55,
            movie:function(){
                console.log(this);//Object { username: "刘德华", age: 55, movie: movie() }
                console.log('拍电影');
            }
        };
        star.movie();
        //3.构造函数this指向是实例化的对象new Mobile('华为',1000)
        function Mobile(brand,price){
            console.log(this);
            this.brand = brand;
            this.price = price;
        }
        var hw = new Mobile('华为',1000);
        //4.定时器里面的this指向Window
        //() => {}  等价于function(){}
        function start(){
            console.log(this);
        }
        //setInterval(start, 10000);
        //5.点击事件
        document.querySelector('button').onclick=function(){
            //DOM对象<button>点击</button>
            console.log(this);
        }

    </script>
</body>
</html>